package com.woniuxy.microsysserver.controller;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.bean.MemberEntity;
import com.woniuxy.bean.ResultBean;
import com.woniuxy.microsysserver.entity.FortuneHeadlinesEntity;
import com.woniuxy.microsysserver.entity.MyPage;
import com.woniuxy.microsysserver.service.FortuneHeadlinesService;
import com.woniuxy.microsysserver.service.IndexService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Auther: wuson  <br/>
 * Date: 2021/4/12:16:45  <br/>
 * Description:
 */
@RefreshScope
@ApiOperation("财富头条")
@Slf4j
@RequestMapping("/sys/fortuneheadlines")
@RestController
public class FortuneHeadlinesController {
    @Autowired(required = false)
    private FortuneHeadlinesService fortuneHeadlinesService;

    @ApiOperation("财富头条信息")
    @PostMapping(value = "/info",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultBean getInfo(@RequestBody MyPage myPage){
        //前端未传分页信息使用默认值
        if(myPage.getPageSize()==0){
            myPage.setPageNum(1);
            myPage.setPageSize(10);
        }
        //开始分页
        PageHelper.startPage(myPage.getPageNum(),myPage.getPageSize());
        List<FortuneHeadlinesEntity> fortuneHeadlinesEntitys = fortuneHeadlinesService.selectAll();
        PageInfo<FortuneHeadlinesEntity> pageInfo = new PageInfo<>(fortuneHeadlinesEntitys);
        return ResultBean.builder().code(200).data(pageInfo).build();
    }
}
